//application
var application = {
 isIE : window.navigator.appName.indexOf("Microsoft") == 0,
 isFF : window.navigator.appName == "Netscape",
 isOpera : window.navigator.appName == "Opera"
};

//ajax
var ajax = {
 method : 'POST',
 create : function(){
 var Ajax = null;
 if(window.XMLHttpRequest){
  Ajax = new XMLHttpRequest();
  if(Ajax.overrideMimeType)Ajax.overrideMimeType("text/xml");
 }else if(window.ActiveXObject){
  try{
   Ajax = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){
   try{
    Ajax = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e2){
    for(var i=3;i<=5;i++){
     Ajax = new ActiveXObject("Msxml2.XMLHTTP."+i+".0");
     if(Ajax)break;
    }
   }
  }
 }
 if(!Ajax){
  alert('Not xmlHttpRequest Object.');return null;
 }
 return Ajax;
 },
 response : function(Ajax,url,readyStateChange){
  var uri = url.split('?');
  var parameter = uri[1];url = uri[0];
  Ajax.open(this.method,url,true);
  Ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  Ajax.send(parameter);
  if(readyStateChange)Ajax.onreadystatechange = readyStateChange;
  },
 request : function(Ajax){
  var read = Ajax.readyState;
  if((read==4||read=='complete')&&(Ajax.status>=200&&Ajax.status<300)){
  var html = Ajax.responseText;
  return html;
  }
 }
};var xml = ajax.create();

function ajax_test(){
 var html = ajax.request(xml);
 if(typeof(html)=='undefined')return;
 alert(html);
}
//DOM
function $(e){
 return document.getElementById(e);
}
function $tag(obj,e){
 return obj.getElementsByTagName(e);
}
function $name(e){
 return document.getElementsByName(e);
}
function $createElement(e){
 return document.createElement(e);
}
function include_css(file){
 var css = $createElement('link');
 css.setAttribute('rel','stylesheet');
 css.setAttribute('type','text/css');
 css.setAttribute('href',file);
 $tag(document,'head')[0].appendChild(css);
}
function include_js(file){
 var js = $createElement('script');
 js.setAttribute('type','text/javascript');
 js.setAttribute('src',file);
 $tag(document,'head')[0].appendChild(js);
}
function addEvent(obj,evt,callback){
 if(window.addEventListener){
  obj.addEventListener(evt,callback,false);
 }else if(window.attachEvent){
  obj.attachEvent('on'+evt,callback);
 }
}
function ready(f){ 
 var a = ready,
 b = navigator.userAgent,
 d = document,
 w = window,
 c = "ready",
 e = "addEventListener",
 o = "opera",
 r = "readyState",
 s = "<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
 a[c] = (function(o){return function(){a[c] = function(){};for(a = arguments.callee; ! a.done; a.done = 1) f(o ? o() : o)}})(a[c]);
 if(d[e])d[e]("DOMContentLoaded",a[c],false);
 if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))(function(){/loaded|complete/.test(d[r])?a[c]():setTimeout(arguments.callee,1)})();
 else if(/MSIE/i.test(b))d.write(s);
};
//RegExp
function is_numeric(number){
 if(number=='')return false;
 var pattern  =  /^[0-9]*$/;
 flag = pattern.test(number); 
 return flag;
}
function is_email(Email){
 var pattern = /^[_a-zA-Z0-9\-\.]+@([\-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
 var flag = pattern.test(Email);
 return flag;
}
function is_mobile(mobile){
 var pattern = /^1(2|3|5|8)\d{9}$/;
 var flag = pattern.test(mobile);
 return flag;
}
function is_phone(phone){
 var pattern = /\d{3}-\d{8}$|\d{4}-\d{7}$/;
 var flag = pattern.test(phone);
 return flag;
}
function is_qq(qq){
 var pattern = /^\d{5,11}$/;
 var flag = pattern.test(qq);
 return flag;
}
function is_url(url){
 var re=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(\S+\.\S+)$/;
 if(empty(url))return false;
 url = url.trim();
 if(url.match(re)==null)return false;
 return true;
}
function is_domain(domain){
 var re=/^(\S+\.\S+)$/;
 if(empty(domain))return false;
 domain = domain.trim();
 if(domain.match(re)==null)return false;
 return true;
}
function is_zip(zip){
 var re=/^\d{6}$/;
 if(zip.match(re)==null)return false;
 return true;
}
function dateDiff(sDate1,sDate2){
 var aDate,oDate1,oDate2,iDays; 
 aDate = sDate1.split("-");
 aDate[2] = aDate[2].substr(0,1) == '0' ? aDate[2].substr(1, aDate[2].length-1) : aDate[2];
 aDate[1] = aDate[1].substr(0,1) == '0' ? aDate[1].substr(1, aDate[1].length-1) : aDate[1];
 oDate1 = new Date(aDate[0],aDate[1]-1,aDate[2]);
 aDate = sDate2.split("-");
 aDate[2] = aDate[2].substr(0,1) == '0' ? aDate[2].substr(1, aDate[2].length-1) : aDate[2];
 aDate[1] = aDate[1].substr(0,1) == '0' ? aDate[1].substr(1, aDate[1].length-1) : aDate[1];
 oDate2 = new Date(aDate[0],aDate[1]-1,aDate[2]);
 iDays = parseInt((oDate2-oDate1)/1000/60/60/24);//把相差的毫秒数转换为天数
 return iDays;
}
function is_null(str){
 return str.trimall()=='';
}
function empty(str){
 return str.trimall()=='';
}
function left(str,len){
 return str.substring(0,len);
}
function get_numeric(str){
 return str.replace(/[^\d]/g,'');
}
//trim
String.prototype.trim = function(){
 return this.replace(/(^\s*)|(\s*$)/g,'');
}
//trimall
String.prototype.trimall = function(){
 return this.replace(/\s/g,'');
}
String.prototype.len = function(){
 var arr = this.match(/[^x00-xff]/ig);
 return this.length + (arr == null ? 0 : arr.length);
}
String.prototype.serverCode = function(){
 return this.replace(/%/g,"&#x25;").replace(/&/g,"＆").replace(/\'/g, "&#39;").replace(/\+/g,"＋").replace(/&lt;/g,"<").replace(/&gt;/g,">");
}
String.prototype.HTMLEncode = function(){
 return this.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
String.prototype.innerText = function(){
 return this.replace(/<[^>]*>/g,"");
}
//Array
Array.prototype.indexOf=function(substr,start){
 var ta,rt,d='\0';
 if(start!=null){ta=this.slice(start);rt=start;}else{ta=this;rt=0;}
 var str=d+ta.join(d)+d,t=str.indexOf(d+substr+d);
 if(t==-1)return -1;rt+=str.slice(0,t).replace(/[^\0]/g,'').length;
 return rt;
}
Array.prototype.lastIndexOf=function(substr,start){
 var ta,rt,d='\0';
 if(start!=null){ta=this.slice(start);rt=start;}else{ta=this;rt=0;}
 ta=ta.reverse();var str=d+ta.join(d)+d,t=str.indexOf(d+substr+d);
 if(t==-1)return -1;rt+=str.slice(t).replace(/[^\0]/g,'').length-2;
 return rt;
}
Array.prototype.replace=function(reg,rpby){
 var ta=this.slice(0),d='\0';
 var str=ta.join(d);str=str.replace(reg,rpby);
 return str.split(d);
}
Array.prototype.search=function(reg){
 var ta=this.slice(0),d='\0',str=d+ta.join(d)+d,regstr=reg.toString();
 reg=new RegExp(regstr.replace(/\/((.|\n)+)\/.*/g,'\\0$1\\0'),regstr.slice(regstr.lastIndexOf('/')+1));
 t=str.search(reg);if(t==-1)return -1;return str.slice(0,t).replace(/[^\0]/g,'').length;
}
Array.prototype.Delete=function(n){
 if(n<0)return this;
 return this.slice(0,n).concat(this.slice(n+1,this.length));
}
function nl2br(str){
 str = str.replace(/\n/g,'<br>');
 return str;
}
function br2nl(str){
 str = str.replace(/<br>/g,'\n');
 str = str.replace(/<br\/>/g,'\n');
 str = str.replace(/<br \/>/g,'\n');
 return str;
}
//url
function header(url){
 top.location = url;
}
function exit(){
 document.body.innerHTML = '';
}
function go_url(url){
 window.location = url;
}
function winreload(){
 window.location.reload();
}
function winclose(){
 window.opener = null;window.close();
}
function winhref(){
 return window.location.href;
}
function win_open(url,width,height){
 var win = window.open(url,'','width='+width+',height='+height+',left=50,top=50,toolbar=no,menubar=no, scrollbars=yes,resizable=no,location=no,status=no');return win;
}
function get(item){
 var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
 return svalue ? svalue[1] : svalue;
}
//event
function getPos(e){
 var y=e.offsetTop;var x=e.offsetLeft;
 while(e=e.offsetParent){y+=e.offsetTop;x+=e.offsetLeft;this.y = y;this.x = x;}
}
function mouseCoords(ev){
 if(ev.pageX || ev.pageY){
 return {x:ev.pageX, y:ev.pageY};
}
return{
 x:ev.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft,
 y:ev.clientY + document.documentElement.scrollTop - document.documentElement.clientTop
 };
}
function showmsg(obj,className,innerHTML){
 $(obj).className = className;$(obj).innerHTML = innerHTML;
}
function setDisplay(obj,display){
 $(obj).style.display = display;
 $(obj).style.zIndex = max_zIndex();
}
function setVisibility(obj,visibility){
 $(obj).style.visibility = visibility;	
}
function setDisabled(obj,disabled){
 $(obj).disabled = disabled;
}
function showbg(obj,top){
 if(!obj)return;
 var clientWidth,clientHeight,scrollHeight,scrollTop,bgHeiht,bg,_top,px,selects,i;
 clientWidth = window.document.body.clientWidth;
 scrollTop = window.top.document.documentElement.scrollTop || window.top.document.body.scrollTop;
 clientHeight = window.top.document.documentElement.clientHeight + scrollTop;
 scrollHeight = window.top.document.documentElement.scrollHeight;
 (scrollHeight>clientHeight) ? bgHeiht = scrollHeight : bgHeiht = clientHeight;
 bg = $createElement('div');
 _top = top || (clientHeight / 2) - $(obj).offsetHeight;
 px = 'px';
 bg.id = 'bg';
 bg.className = 'alpha';
 with(bg.style){
  width = clientWidth + px;
  height = scrollHeight + px;
  position = 'absolute';
  left = '0' + px;
  top = '0' + px;
  zIndex = max_zIndex() - 1;
  filter = 'Alpha(Opacity=20)';
  MozOpacity = '0.2';
 }
 selects = $tag(document,'select');
 for(i=0;i<selects.length;i++)selects[i].style.visibility = 'hidden';
 selects = $tag($(obj),'select');
 for(i=0;i<selects.length;i++)selects[i].style.visibility = 'visible';
 if(!$('bg'))document.body.appendChild(bg);
 with($(obj).style){
  position = 'absolute';display = 'block';zIndex = max_zIndex();
  top = (scrollTop + _top) + px;
  left = ((clientWidth/2)-($(obj).offsetWidth/2)) + px;
 }
 window.onscroll = function(){
  //$(obj).style.top = (document.documentElement.scrollTop + _top) + px;
 }
}
function hidebg(obj){
 if($(obj))$(obj).style.display = 'none';
 if($('bg'))document.body.removeChild($('bg'));
 var selects = $tag(document,'select');
 for(var i=0;i<selects.length;i++)selects[i].style.visibility = 'visible';
 window.onscroll = null;
}
function msgbox(title,msg,width,top){
 var obj = 'box';
 var div = $createElement('div');
 var px = 'px';
 with(div){
  id = obj;
  className = obj;
  style.width = width + px;
  style.position = 'absolute';
  style.top = top + px;
 }
 div.innerHTML = "<div class='title'><div class='left'>"+title+"</div><div class='right'><img id='msgbox_close_btn' src='../images/close.gif' alt='关闭' onclick=\"hide_msgbox()\"; /></div></div><div class='content' style='padding:10px;background:#fff;' id='box_content'>"+msg+"</div>";
 document.body.appendChild(div);
 Drag.init(div.firstChild,div);
 showbg(obj,top);
}
function hide_msgbox(){
 var obj = 'box';
 if(!$(obj))return;
 $(obj).innerHTML = '';
 document.body.removeChild($(obj));
 hidebg(obj);
}
function show_hide(obj){
 ($(obj).style.display=='none'||empty($(obj).style.display)) ? setDisplay(obj,'block') : setDisplay(obj,'none');
}
//获取最大zIndex
function max_zIndex(){
/*var div = $tag(document,'div');
 var len = div.length;
 if(len==0)return 0;
 var maxZindex = 0;
 var maxIndex = 1;
 for(var i=maxIndex;i<len;i++)if(maxZindex<div[i].style.zIndex)maxZindex = div[i].style.zIndex;maxIndex = i;
 return parseInt(maxZindex)+1;*/
 return 2147483647;
}
//
function get_number(str){
 return str.replace(/[^\d]/g,'');
}
//是否是时间格式
function is_date(sDate){
 var iYear,iMonth,iDay,iIndex
 var reg;
 reg = new RegExp('[^0-9-]','')
 if(sDate.search(reg)>=0)return false;
 iIndex = sDate.indexOf('-');
 if(iIndex==-1)return false;
 iYear = parseFloat(sDate.substr(0,iIndex));
 if(isNaN(iYear)||iYear<1900||iYear>2099)return false;
 sDate = sDate.substring(iIndex+1,sDate.length);
 iIndex = sDate.indexOf('-');
 if(iIndex==-1)return false;
 iMonth = parseFloat(sDate.substr(0, iIndex));
 if(isNaN(iMonth)||iMonth < 1||iMonth>12)return false;
 sDate = sDate.substring(iIndex + 1, sDate.length);
 iIndex = sDate.indexOf('-');
 if(iIndex>=0)return false;
 iDay = parseFloat(sDate);
 if(isNaN(iDay)||iDay<1||iDay>31)return false;
 switch(iMonth){
  case 4:
  case 6:
  case 9:
  case 11:if(iDay>30)return false;
  break;
  case 2:
   if(((iYear%4==0&&iYear%100!=0)||iYear%400==0)&&iDay>29)return false;
   if((iYear%4!=0||(iYear%100==0&&iYear%400!=0))&&iDay>28)return false;
  break;
 }
 return true;
}
//复制内容到剪贴板
function clipboard(data){
 window.clipboardData.setData('Text',data);
}